<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>河北科技学院教务系统登陆</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script src="http://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.validate.js"></script>
    <style type="text/css">
    .login_zhuce{
		float: right!important;
		}
	#loginForm{
	width:500px;
	}
	.jumbotron{
	height:600px;
	margin-top:100px;
	}
	.yanzhenma{
		width:400px;
		float:left;
		display:inline;
		}
</style>
  </head>
  <body>
    <div class="jumbotron">
  <div class="container" align="center">
      <h2 class="text-info" style="font-family:宋体;font-weight:bold;font-size:49px">教务系统登陆</h2>
      <form  id="loginForm" name="loginForm" action="<%=path%>/student/login" method="post">
   		<input class="form-control" type="text" name="username" placeholder="用户名"/><br>
  		<input class="form-control" type="password" name="password" placeholder="密码"/><br>
  		<select class="form-control" id="juese" onchange="choice()">
   			<option value="1" selected="selected">学生</option>
   			<option value="2">老师</option>
		</select><br>
		<input class="form-control yanzhenma" type="text" name="yanzhenma" placeholder="验证码"/>
		
		<span><a href="javascript: reloadCode();">
		<img class="img-rounded" alt="验证码" id="imagecode" src="<%=request.getContextPath() %>/student/pictory"/>
    </a></span><br>
   			 <div>
				<a href="#" class="login_zhuce text-primary" data-toggle="modal" data-target="#myModal1">忘记密码</a> 
			</div>
        <br />
 
  		<input type="submit" class="btn btn-lg btn-primary" value="登录">
    </form> 
  </div>
  <!--模态窗口 1-->
  <div class="modal fade" id="myModal1"  data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
            <h4 class="modal-title">密码找回(暂只支持老师)</h4>
          </div>
          <div class="modal-body">
   		   <input class="form-control" type="text" id="ID" placeholder="用户名"/><br>
          	</div>
            <div class="modal-footer">
            <button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
            <button class="btn btn-primary"  id="tijiao1" type="button">提交</button>
         	 </div>
        </div><!-- /.modal-content -->
      </div><!-- /.modal-dialog -->
</div>


<!--模态窗口2-->
  <div class="modal fade" id="myModal2"  data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
            <h4 class="modal-title">密码找回(暂只支持老师)</h4>
          </div>
          <div class="modal-body">
   		   <input class="form-control"  readonly="readonly" type="text" id="mibao" placeholder="密保问题"/><br>
   		   <input class="form-control" type="text" id="mibaoAnswer" placeholder="密保答案"/><br>
   		   <input class="form-control" type="password" id="npassword" placeholder="新密码"/><br>
          </div>
            <div class="modal-footer">
            <button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
            <button class="btn btn-primary"  id="tijiao2" type="button">提交</button>
         	 </div>
        </div><!-- /.modal-content -->
      </div><!-- /.modal-dialog -->
</div>
  
</div>

<script type="text/javascript">

//模态窗口1
$("#tijiao1").bind("click", function () {
                    $.ajax({
                        url: "teacher/Idmibao",
                        data: { num: $("#ID").val() },
                        type: 'POST',
                        success: function (data) {
                           $("#mibao").val(data);
                           $("#myModal1").modal("toggle");
                           $("#myModal2").modal("show");
                        }
                    });
                });

//模态窗口2
$("#tijiao2").bind("click", function () {
                    $.ajax({
                        url: "teacher/mibaoCpassword",
                        data: { num1: $("#mibaoAnswer").val(), num2:$("#npassword").val() },
                        type: 'POST',
                        success: function (data) {
                         	 alert(data);
                           $("#myModal2").modal("toggle");
                           
                        }
                    });
                });

//验证码刷新
function reloadCode(){
			var time = new Date().getTime();
			document.getElementById("imagecode").src="<%=request.getContextPath() %>/student/pictory?d="+time;
		}

//进行角色选择
 function choice(){
  var type=document.getElementById("juese");
  var name=type.options[type.selectedIndex].value;
  if(name==1){
  document.getElementById("loginForm").action="<%=path%>/student/login";
  }
  if(name==2){
  document.getElementById("loginForm").action="<%=path%>/teacher/login";
  }
  }
  //验证成功后，触发事件
  $.validator.setDefaults({
    submitHandler: function() {
      alert("成功提交!");
      form.submit();
    }
});
//表单验证
  $().ready(function() {
  $("#loginForm").validate({
  rules:{
  	username:{
  	required:true,
  	number:true,
  	minlength:10
  	},
  	password:{
  	required:true
  	},
  	yanzhenma:{
  	required:true
  	}
  },
  messages:{
  	username:{
  		required:"请输入用户名",
  		number:"格式不对"
  	},
  	password:{
		 required:"请输入密码"	
  	},
  	yanzhenma:{
  		required:"请输入验证码"	
  	}
  }
  
  });
  });
  </script>
  </body>
</html>
